/*
 * ButtonScanner.cpp
 *
 * This class models the LED Display that displays the
 * all the data provided by the cyclometer device
 *
 * Author: Zachary Masiello
 * Author: Peter-John Rowe
 */

#include "ButtonScanner.h"
#include <unistd.h>

#define MODE 1
#define SS 2
#define SET 3
#define ALL 4
#define SSMODE 5

// Constructor
ButtonScanner::ButtonScanner(ButtonPort *newButtonPort, Cyclometer *newCyclometer)
{
	buttonPort = newButtonPort;
	cyclometer = newCyclometer;
}

// Destructor
ButtonScanner::~ButtonScanner()
{
	// TODO Auto-generated destructor stub
}

// For the thread that controls the input from the buttons to
	// throw events (button presses)
void* ButtonScanner::run(ButtonScanner * buttonScanner)
{
	while(true)
	{
		int input = buttonScanner->buttonPort->scanInput();
		switch(input)
		{
		case MODE:
			buttonScanner->cyclometer->accept(new ModeButtonPressEvent());
			break;
		case SET:
			buttonScanner->cyclometer->accept(new SetButtonPressEvent());
			break;
		case SS:
			buttonScanner->cyclometer->accept(new SSButtonPressEvent());
			break;
		case ALL:
			buttonScanner->cyclometer->accept(new AllButtonPressEvent());
			break;
		case SSMODE:
			buttonScanner->cyclometer->accept(new SSModeButtonPressEvent());
			break;
		}
		sleep(1);
	}

}
